<?php

header("Content-type:text/html;charset=utf-8");

if(!empty($_POST['submit'])){
	$username = $_POST['username'];
	$content = $_POST['content'];
	if($username == '' || strlen($username) > 10){
	echo <<<tem
			<script type="text/javascript">
				alert("请输入正确的用户名");
				location.href="post.html";
			</script>
tem;
	exit();
	}
	require('config.inc.php');
	$content_time = time();
	$insertSql = "insert into info (name,content,content_time) values ('$username','$content','$content_time')";
	mysql_query("set names utf8");
	if(mysql_query($insertSql)){
		echo <<<TEM
		<script>
			alert("留言成功！");
			location.href="index.php";
		</script>
	TEM;
	}else{
		echo <<<TEM
		<script>
			alert("留言失败！");
			location.href="index.php";
		</script>
TEM;
	}
}


?>